/**
 * @param {string} s
 * @return {boolean}
 */
var repeatedSubstringPattern = function (s) {
    let sLen = s.length,
        mid = ~~((sLen - 1) / 2)

    if (sLen <= 1) return false
    // 子串的长度需小于等于原串的一半
    for (let i = 0; i <= mid; i++) {
        let subLength = i + 1
        let substr = s.slice(0, subLength)

        let flag = true
        for (let j = i + 1; j < sLen; j += subLength) {
            let str = s.slice(j, j + subLength)
            if (substr !== str) {
                flag = false
                break
            }
        }
        if (flag) {
            return flag
        }
    }

    return false
};

/**
 * @param {string} s
 * @return {boolean}
 */
var repeatedSubstringPattern = function (s) {
    let sLen = s.length
    if (sLen <= 1) return false

    // 子串的长度需小于等于原串的一半
    for (let i = 1; i * 2 <= sLen; i++) {
        if (sLen % i === 0) {
            let flag = true
            // 对字符串进行匹配，每隔i个字符判断是否相等
            for (let j = i; j < sLen; j++) {
                if (s[j] !== s[j - i]) {
                    flag = false
                    break
                }
            }
            if (flag) {
                return flag
            }
        }
    }

    return false
};

/**
 * @param {string} s
 * @return {boolean}
 */
var repeatedSubstringPattern = function(s) { 
    // 将原字符串拼接自身，然后去掉首尾字符
    let s1 = (s + s).slice(1, -1)
    // 如果拼接后的字符串包含原字符串，则说明可由重复子串构成
    return s1.indexOf(s) !== -1
};

/**
 * @param {string} s
 * @return {boolean}
 */
var repeatedSubstringPattern = function(s) {
    return (s + s).indexOf(s, 1) !== s.length
};

console.log(repeatedSubstringPattern("abcabcabcabc"))